<template>
    <div>
        <div class="container">
             <div class="handle-box">
              <el-row type="flex" class="row-bg" justify="space-between">
                <el-col>
                   <el-select v-model="query.address" placeholder="年度" class="handle-select mr10">
                        <el-option key="1" label="2020" value="2020"></el-option>
                        <el-option key="2" label="2021" value="2021"></el-option>
                    </el-select>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                </el-col>
               <el-button type="primary" icon="el-icon-plus" @click="handleSearch">新增</el-button>
              </el-row>
               
            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                header-cell-class-name="table-header"
            >
                <el-table-column prop="year" label="考核年度" width="150" align="center"></el-table-column>
                <el-table-column prop="name" label="项目名称"> 
                </el-table-column>
                <el-table-column prop="time" label="提交时间"></el-table-column>
                <el-table-column label="操作"  align="center">
                    <template slot-scope="scope">
                        <el-button
                            type="primary"
                            
                            @click="$emit('close')"
                        >编辑</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

    </div>
</template>

<script>
import { fetchData } from '../../../api/index';


import {data} from '@/components/common/area';
export default {
    name: 'kaoheman',
    components: {

    },
    props: {
        isComponent: {
            dafault: false,
            type: Boolean
        },
        type: {
            default: "",
            type: String
        }
    },
    data() {
        return {
            data: data,
            formInline: {
                year: ''
            },
           
            query: {
                address: '',
                name: '',
                pageIndex: 1,
                pageSize: 10
            },
            tableData: [{
                code: 'ST-213326330',
                name: '瓦山区蓄水保土耕作项目',
                year: 2021,
                guanlidanwei: '平顶建设',
                hangye: '水土保护建设行业',
                time: '2021-03-18',
                xingzhi: 1,
                liuyuguanlijigou: '南昌县水利局',
                shejisheng: '江西省南昌市',
                shejiqu: '南昌县',
                fangzhizeren: 1,
                fanganshangbao: 2,
                jishushencha: 2,
                fanganpifu: 2,
                jianshejindu: 40,
                jianchacishu: 3,
                jianli: 1,
                shuitubaochi: 1,
            },{
                code: 'ST-213326331',
                name: '平定区蓄水保土耕作项目',
                year: 2021,
                guanlidanwei: '平顶建设',
                hangye: '水土保护建设行业',
                time: '2021-03-18',
                xingzhi: 1,
                liuyuguanlijigou: '南昌县水利局',
                shejisheng: '江西省南昌市',
                shejiqu: '南昌县',
                fangzhizeren: 0,
                fanganshangbao: 1,
                jishushencha: 1,
                fanganpifu: 1,
                jianshejindu: 0,
                jianchacishu: 3,
                jianli: 1,
                shuitubaochi: 1,
            }],
            multipleSelection: [],
            delList: [],
            innerTableVisible: false,
            pageTotal: 2,
            form: {},
            idx: -1,
            id: -1
        };
    },
    created() {
        let that=this
        //that.getData();
    },
    methods: {
        // 获取 easy-mock 的模拟数据
        getData() {
            fetchData(this.query).then(res => {
               
                this.tableData = res.list;
                this.pageTotal = res.pageTotal || 50;
            });
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'pageIndex', 1);
            this.getData();
        },
        // 删除操作
        handleDelete(index, row) {
            // 二次确认删除
            this.$confirm('确定要删除吗？', '提示', {
                type: 'warning'
            })
                .then(() => {
                    this.$message.success('删除成功');
                    this.tableData.splice(index, 1);
                })
                .catch(() => {});
        },
        // 多选操作
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        delAllSelection() {
            const length = this.multipleSelection.length;
            let str = '';
            this.delList = this.delList.concat(this.multipleSelection);
            for (let i = 0; i < length; i++) {
                str += this.multipleSelection[i].name + ' ';
            }
            this.$message.error(`删除了${str}`);
            this.multipleSelection = [];
        },
        // 编辑操作
        handleEdit(index, row, disabled) {
            this.idx = index;
            this.form = row;
            this.form = {...row, disabled}
            this.innerTableVisible = true;
        },
        // 保存编辑
        saveEdit() {
            this.innerTableVisible = false;
            this.$message.success(`修改第 ${this.idx + 1} 行成功`);
            this.$set(this.tableData, this.idx, this.form);
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        },
        onSubmit() {},
        checkSubmit() {
            let {num} = this.formInline;
            
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
